/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apt;

import java.util.Scanner;

/**
 *
 * @author lhminh
 */
public class MangSoThuc {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        double[] a = nhap();
        xuat(a);
        xuatsoDuong(a);
        double kq1 = tongAm(a);
        System.out.println("\nTong am la: " + kq1);
        double kq2 = tongDuong(a);
        System.out.println("\nTong duong la: " + kq2);
    }
    
    public static double[] nhap() {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Nhap n: ");
        int n = scanner.nextInt();
        double[] kq = new double[n];
        
        for (int i = 0; i < n; i++) {
            System.out.print("Nhap a[" + i + "] = ");
            kq[i] = scanner.nextDouble();
        }
        
        return kq;
    }
    
    public static void xuat(double[] a) {
        for (int i = 0; i < a.length; i++) {
            System.out.printf("%8.2f", a[i]);
        }
    }
    public static void xuatsoDuong(double[] a) {
        for (int i = 0; i < a.length; i++) {
            if(a[i]>0){
                System.out.printf("%8.2f", a[i]);
            }
        }
    }
    public static double tongAm(double[] a) {
        double kq = 0;
        
        for (int i = 0; i < a.length; i++) {
            if (a[i] < 0) {
                kq = kq + a[i];
            }
        }
        
        return kq;
    }
    public static double tongDuong(double[] a) {
        double kq = 0;
        
        for (int i = 0; i < a.length; i++) {
            if (a[i] >= 0) {
                kq = kq + a[i];
            }
        }
        
        return kq;
    }
}
